/**
 * @fileoverview Description of this file.
 */

surveydata = [
  {question: 'When you saw the article what part of it grabbed your attention first?',
   answers: ['Diagram', 'Text']},
  {question: 'What part of the article did look at more carefully?',
   answers: ['Diagram', 'Text']},
  {question: 'Did you notice redundancy between the text and the diagram?',
   answers: ['Yes', 'No']},
  {question: 'Which part of the article do you think you could remember better now?',
   answers: ['Diagram', 'Text', 'Both equally', 'Neither']},
  {question: 'Did the diagram help you understand the text?',
   answers: ['Yes', 'No, I still don\'t understand the diagram',
             'No need, I understood the diagram already']},
  {question: 'Please briefly summarize the article you read in a few words:'},
  {question: 'Please provide us with general comments.'}];

SurveyStart =
  '<div id="survey"><p>Please complete the survey:</p>' +
  //'<form id="mturk_form" method="POST" action="http://www.mturk.com/mturk/externalSubmit">' +
  '<form id="mturk_form" method="POST" action="http://workersandbox.mturk.com/mturk/externalSubmit">' +
  '<input type="hidden" id="assignmentId" name="assignmentId" value="%assignId">' +
  '<input type="hidden" id="logs" name="logs" value="[%logs]">';

SurveyQuestionTemplate = '<p class="survey-question">%question</p>';
SurveyRadioAnswerTemplate = '<table cellspacing="4" cellpadding="0" border="0">' +
  '<tbody>%answer</tbody></table>';

SurveyRadioAnswerItemTemplate =
  '<tr><td valign="center" width="20px"><input type="radio" value="%value" name="Q%i" /></td>' +
    '<td><span class="answertext">%answer</span></td></tr>';

SurveyTextAnswerTemplate = '<p><input type="text" size="80" name="Q%i" /></p>';

SubmitButton = '<p>Please submit the survey.  Thank you for your participation!</p>' +
    '<input id="submitButton" type="submit" name="Submit" class="centralbutton" value="Submit">' +
    '</form></div>';

function createSurveyPage() {
  var html = SurveyStart
      .replace('%assignId', assignId)
      .replace('%logs', globalReplace(logs, '"', '\''));

  for (var i = 0; i < surveydata.length; i++) {
    var data = surveydata[i];
    var question = SurveyQuestionTemplate.replace('%question', data.question);
    var answers = ''
    if (data.answers) {
      var items = ''
      for (var j = 0; j < data.answers.length; j++) {
        items += SurveyRadioAnswerItemTemplate
            .replace('%answer', data.answers[j])
            .replace('%value', data.answers[j])
            .replace('%i', i);
      }
      answers = SurveyRadioAnswerTemplate.replace('%answer', items);
    } else {
      answers = SurveyTextAnswerTemplate.replace('%i', i);
    }
    html += question + answers;
  }

  setFullInstruction(html + SubmitButton);

  var fiButton = document.getElementById('fi-button');
  fiButton.style.display = 'none';    
}
